import { JSONValue } from '@keystone-next/types';
import { gql } from './apollo';

export const staticAdminMetaQuery = gql`
  query StaticAdminMeta {
    keystone {
      __typename
      adminMeta {
        __typename
        enableSignout
        enableSessionItem
        lists {
          __typename
          key
          itemQueryName
          listQueryName
          initialSort {
            __typename
            field
            direction
          }
          path
          label
          singular
          plural
          description
          initialColumns
          pageSize
          labelField
          fields {
            __typename
            path
            label
            isOrderable
            fieldMeta
            views
            customViews
          }
        }
      }
    }
  }
`;

// generated by https://graphql-code-generator.com with these options:
// generates:
//   types.ts:
//     plugins:
//       - typescript-operations:
//           namingConvention: keep
//       - typescript:
//           enumsAsTypes: true
//           nonOptionalTypename: true
//           namingConvention: keep
//           noExport: true
//           avoidOptionals: true
//           scalars:
//             JSON: JSONValue

type Maybe<T> = T | null;

export type StaticAdminMetaQuery = { __typename?: 'Query' } & {
  keystone: { __typename: 'KeystoneMeta' } & {
    adminMeta: { __typename: 'KeystoneAdminMeta' } & Pick<
      KeystoneAdminMeta,
      'enableSignout' | 'enableSessionItem'
    > & {
        lists: Array<
          { __typename: 'KeystoneAdminUIListMeta' } & Pick<
            KeystoneAdminUIListMeta,
            | 'key'
            | 'itemQueryName'
            | 'listQueryName'
            | 'path'
            | 'label'
            | 'singular'
            | 'plural'
            | 'description'
            | 'initialColumns'
            | 'pageSize'
            | 'labelField'
            | 'initialSort'
          > & {
              fields: Array<
                { __typename: 'KeystoneAdminUIFieldMeta' } & Pick<
                  KeystoneAdminUIFieldMeta,
                  'path' | 'label' | 'isOrderable' | 'fieldMeta' | 'views' | 'customViews'
                >
              >;
            }
        >;
      };
  };
};

/** All built-in and custom scalars, mapped to their actual values */
type Scalars = {
  ID: string;
  String: string;
  Boolean: boolean;
  Int: number;
  Float: number;
  JSON: JSONValue;
};

export type Query = {
  __typename: 'Query';
  keystone: KeystoneMeta;
};

type KeystoneMeta = {
  __typename: 'KeystoneMeta';
  adminMeta: KeystoneAdminMeta;
};

type KeystoneAdminMeta = {
  __typename: 'KeystoneAdminMeta';
  enableSignout: Scalars['Boolean'];
  enableSessionItem: Scalars['Boolean'];
  lists: Array<KeystoneAdminUIListMeta>;
  list: Maybe<KeystoneAdminUIListMeta>;
};

type KeystoneAdminUIListMeta = {
  __typename: 'KeystoneAdminUIListMeta';
  key: Scalars['String'];
  itemQueryName: Scalars['String'];
  listQueryName: Scalars['String'];
  hideCreate: Scalars['Boolean'];
  hideDelete: Scalars['Boolean'];
  path: Scalars['String'];
  label: Scalars['String'];
  singular: Scalars['String'];
  plural: Scalars['String'];
  description: Maybe<Scalars['String']>;
  initialColumns: Array<Scalars['String']>;
  pageSize: Scalars['Int'];
  labelField: Scalars['String'];
  fields: Array<KeystoneAdminUIFieldMeta>;
  initialSort: Maybe<KeystoneAdminUISort>;
};

type KeystoneAdminUISort = {
  __typename: 'KeystoneAdminUISort';
  field: Scalars['String'];
  direction: KeystoneAdminUISortDirection;
};

type KeystoneAdminUIFieldMeta = {
  __typename: 'KeystoneAdminUIFieldMeta';
  path: Scalars['String'];
  label: Scalars['String'];
  isOrderable: Scalars['Boolean'];
  fieldMeta: Maybe<Scalars['JSON']>;
  views: Scalars['Int'];
  customViews: Maybe<Scalars['Int']>;
  createView: KeystoneAdminUIFieldMetaCreateView;
  listView: KeystoneAdminUIFieldMetaListView;
  itemView: Maybe<KeystoneAdminUIFieldMetaItemView>;
};

type KeystoneAdminUIFieldMetaCreateView = {
  __typename: 'KeystoneAdminUIFieldMetaCreateView';
  fieldMode: KeystoneAdminUIFieldMetaCreateViewFieldMode;
};

type KeystoneAdminUIFieldMetaListView = {
  __typename: 'KeystoneAdminUIFieldMetaListView';
  fieldMode: KeystoneAdminUIFieldMetaListViewFieldMode;
};

type KeystoneAdminUIFieldMetaItemView = {
  __typename: 'KeystoneAdminUIFieldMetaItemView';
  fieldMode: KeystoneAdminUIFieldMetaItemViewFieldMode;
};

type KeystoneAdminUIFieldMetaCreateViewFieldMode = 'edit' | 'hidden';

type KeystoneAdminUIFieldMetaListViewFieldMode = 'read' | 'hidden';

type KeystoneAdminUIFieldMetaItemViewFieldMode = 'edit' | 'read' | 'hidden';

type KeystoneAdminUISortDirection = 'ASC' | 'DESC';

// a copy of StaticAdminMetaQuery but without the typenames written manually + & { listKey: string } on fields
export type StaticAdminMetaQueryWithoutTypeNames = {
  keystone: {
    adminMeta: Pick<KeystoneAdminMeta, 'enableSignout' | 'enableSessionItem'> & {
      lists: Array<
        Pick<
          KeystoneAdminUIListMeta,
          | 'key'
          | 'itemQueryName'
          | 'listQueryName'
          | 'path'
          | 'label'
          | 'singular'
          | 'plural'
          | 'description'
          | 'initialColumns'
          | 'pageSize'
          | 'labelField'
        > & {
          fields: Array<
            Pick<
              KeystoneAdminUIFieldMeta,
              'path' | 'label' | 'isOrderable' | 'fieldMeta' | 'views' | 'customViews'
            > & { listKey: string }
          >;
          initialSort: Maybe<{ field: Scalars['String']; direction: KeystoneAdminUISortDirection }>;
        }
      >;
    };
  };
};
